package model.mail;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailHelper {
	public static void send(String fromAddr, String fromName, String toAddr, String toName, String subject,
			String msgBody) {
	    try {
	    	Properties props = new Properties();
			Session mailSession = Session.getDefaultInstance(props, null);
			MimeMessage msg = new MimeMessage(mailSession);
			
			msg.setFrom(new InternetAddress(fromAddr, fromName, "utf-8"));
			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(toAddr, toName, "utf-8"));
		    msg.setSubject(subject, "utf-8");
		    msg.setText(msgBody);
		    Transport.send(msg);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (MessagingException e) {
			e.printStackTrace();
		}   
	}
}
